/**
 * 粗盐样品瓶
 */
SampleBottle = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_SALT_BOTTLE);
	},
	init:function(){
		this.body = new Button(this, 10, TAG_SALT, "#salt.png", this.callback);
		this.body2 = new cc.Sprite("#salt2.png");
		this.addChild(this.body2, 5);
		var lid = new Button(this, 10, TAG_LID, "#lid.png", this.callback);
		lid.setPosition(0,40);
		
		var spoon = new Button(this, 8, TAG_SPOON, "#spoon.png", this.callback);
		spoon.setPosition(150,0);
		
		var label = new cc.LabelTTF("粗盐",gg.fontName,12);
		label.setColor(cc.color(0,0,0));
		label.setPosition(25, 36);
		this.body.setCascadeOpacityEnabled(true);
		this.body.addChild(label, 11);
	},
	openLid:function(){
		var ber = cc.bezierBy(1.5,[cc.p(50,70),cc.p(60,-70),cc.p(60,-75)]);
		var rotate = cc.rotateTo(1.5, 180);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,this.func);
		this.getChildByTag(TAG_LID).runAction(seq);
	},
	rotateBody:function(obj){
		var rotate1 = cc.rotateTo(1,65);
		var delay = cc.delayTime(0.8);
		var rotate2 = cc.rotateTo(1,0);
		var seq = cc.sequence(rotate1,delay,rotate2);
		obj.runAction(seq);
	},
	callback:function(p){
		switch(p.getTag()){
		case TAG_LID:
			this.openLid();
			break;
		case TAG_SPOON:
			var move1 = cc.moveTo(0.4,cc.p(100, 50));
			var rotate = cc.rotateTo(0.2,15);
			var move2 = cc.moveTo(0.4,cc.p(30,20));
			var delay = cc.delayTime(0.8);
			var func = cc.callFunc(function(p){
				p.setSpriteFrame("spoon2.png");
			}.bind(p),this);
			var move3 = cc.moveTo(0.5,cc.p(100,50));
			var ber = cc.bezierTo(1,[cc.p(120,250),cc.p(300,200),cc.p(360,60)]);
			var seq = cc.sequence(move1,rotate,move2,delay,func,move3,ber,this.func);
			p.runAction(seq);
			this.rotateBody(this.body);
			this.rotateBody(this.body2);
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
		case TAG_LID:
			p.setRotation(0);
			p.setSpriteFrame("lid2.png");
			gg.flow.next();
			break;
		case TAG_SPOON:
			this.setCascadeOpacityEnabled(true);
			var seq = cc.sequence(cc.delayTime(0.5), this.getParent().callKill);
			this.runAction(seq);
			
			// 天平上出现粗盐
			var paper = this.getParent().getChildByTag(TAG_PAPER);
			var salt = new cc.Sprite("#salt5.png");
			salt.setOpacity(0);
			salt.setPosition(50,25);
			paper.setCascadeOpacityEnabled(true);
			paper.addChild(salt);
			salt.runAction(cc.fadeTo(0.5, 255));
	
			// 天平出现指针
			this.getParent().balance.showDisk();
			break;
		}
	},
});